import 'package:baseProjectFlutter/utils/other/log/log.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:baseProjectFlutter/widgets_common/image/svg_widget.dart';

import 'generated/assets.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Container(
          width: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
              ),
              ElevatedButton(
                  onPressed: () {
                    LogUtils.e("Button pressed");
                  },
                  child: const Text("ElevatedButton")),
              TextButton(
                  onPressed: () {
                    LogUtils.e("TextButton pressed");
                  },
                  child: const Text("TextButton")),
              OutlinedButton(
                  onPressed: () {
                    LogUtils.e("OutlinedButton pressed");
                  },
                  child: const Text("OutlinedButton")),
              IconButton(
                  onPressed: () {
                    LogUtils.e("IconButton pressed");
                  },
                  icon: const Icon(Icons.sensor_occupied_rounded)),
              ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    padding: EdgeInsets.zero, // 去除内边距
                    backgroundColor: Colors.blue, // 背景色,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10)),
                    minimumSize: const Size(double.minPositive, 30),
                  ),
                  onPressed: () {
                    LogUtils.e("ElevatedButton Custom pressed");
                  },
                  child: const Text("ElevatedButton Custom")),
              const Text("Row"),
              Container(
                constraints: const BoxConstraints(
                  maxWidth: 200,
                  maxHeight: double.infinity,
                ),
                color: Colors.red,
                padding: const EdgeInsets.all(10),
                child: Text(
                  "aaaaaaaaaaabwwwwwwwwwbbbbbbbbbb$_counter",
                  softWrap: false,
                  overflow: TextOverflow.clip,
                  maxLines: 3,
                  style: const TextStyle(fontSize: 20),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: 10),
                constraints: const BoxConstraints(
                  maxWidth: 200,
                  maxHeight: 40,
                ),
                child: TextField(
                  decoration: const InputDecoration(
                    contentPadding: EdgeInsets.all(10),
                    hintText: "输入1",
                    border: OutlineInputBorder(),
                    floatingLabelBehavior: FloatingLabelBehavior.never,
                  ),
                  keyboardType: TextInputType.number,
                  inputFormatters: [
                    // FilteringTextInputFormatter.digitsOnly,
                    // 只允许输入数字
                    FilteringTextInputFormatter.allow(RegExp(r'^\d+\.?\d*$')),
                    // 只允许输入数字和小数点
                  ],
                  onChanged: (value) {
                    LogUtils.e("输入1改变: $value");
                  },
                ),
              ),
              Image.asset(
                Assets.imgIcTips,
                width: 100,
                height: 100,
              ),
              SvgWidget(Assets.svgIcSuccess, width: 100, height: 100),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        heroTag: hashCode,
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}